home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / QuickTime / QuickTime VR / Make QTVR Panorama / CPict2VRWindow.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  8.4 KB  |  373 lines  |  [TEXT/CWIE]

  1. /*
  2.     A window that provides a user interface for creating QTVR movies.
  3.     
  4.     Created 29 Jan 1996 by EGH
  5.     
  6.     Copyright © 1996, Apple Computer, Inc. All rights reserved.
  7. */
  8.  
  9. #include <QuickTimeComponents.h>
  10.  
  11. #include <String_Utils.h>
  12.  
  13. #include "CApp.h"
  14. #include "CBeachBall.h"
  15. #include "CKeyFilters.h"
  16. #include "CMovieMaker.h"
  17. #include "CUtils.h"
  18.  
  19. #include "CPict2VRWindow.h"
  20.  
  21. // =========
  22. // constants
  23.  
  24. const PaneIDT Button_Create = 'okay';
  25. const PaneIDT Button_Cancel = 'canc';
  26. const PaneIDT Button_MakeDefault = 'defa';
  27. const PaneIDT Button_Compression = 'comp';
  28. const PaneIDT Caption_Compression = 'coms';
  29. const PaneIDT Caption_PictFile = 'pict';
  30. const PaneIDT Caption_TileFile = 'tile';
  31. const PaneIDT Caption_QTVRFile = 'move';
  32. const PaneIDT Button_SetVRFile = 'setf';
  33. const PaneIDT Button_SetTileFile = 'sett';
  34. const PaneIDT Edit_Width = 'widt';
  35. const PaneIDT Edit_Height = 'heig';
  36. const PaneIDT Edit_Pan = 'pan ';
  37. const PaneIDT Edit_Tilt = 'tilt';
  38. const PaneIDT Edit_Zoom = 'zoom';
  39.  
  40. // =========
  41.  
  42.  
  43. //static
  44. CPict2VRWindow *CPict2VRWindow::CreatePict2VRWindowWindowStream(
  45.     LStream    *inStream)
  46. {
  47.     return new CPict2VRWindow(inStream);
  48. }
  49.  
  50. CPict2VRWindow::CPict2VRWindow(
  51.     LStream    *inStream) :
  52.     LDialogBox(inStream)
  53. {
  54. }
  55.  
  56. CPict2VRWindow::~CPict2VRWindow()
  57. {
  58. }
  59.  
  60. void CPict2VRWindow::FinishCreateSelf()
  61. {
  62.     LDialogBox::FinishCreateSelf();
  63.     AddAttachment(new LUndoer); // for the edits
  64.     
  65.     mDepth = 32;
  66.     mSpatialQuality = codecHighQuality;
  67.     mCodec = 'cvid';
  68.     
  69.         // check the app for default parameters
  70.     P2VRPrefsHdl prefs = gApp->GetPreferences();
  71.     if (prefs != nil)
  72.     {
  73.         mDepth = (*prefs)->depth;
  74.         mSpatialQuality = (*prefs)->spatialQuality;
  75.         mCodec = (*prefs)->codec;
  76.         
  77.         SetValueForPaneID(Edit_Width, (*prefs)->width);
  78.         SetValueForPaneID(Edit_Height, (*prefs)->height);
  79.         
  80.         Str255 valueStr;
  81.         LEditField *pane = (LEditField *)FindPaneByID(Edit_Pan);
  82.         if (pane != nil)
  83.         {
  84.             pane->SetKeyFilter(CKeyFilters::RealNumberFieldPositive);
  85.             FixedToStr((*prefs)->pan, valueStr);
  86.             pane->SetDescriptor(valueStr);
  87.         }
  88.         pane = (LEditField *)FindPaneByID(Edit_Tilt);
  89.         if (pane != nil)
  90.         {
  91.             pane->SetKeyFilter(CKeyFilters::RealNumberField);
  92.             FixedToStr((*prefs)->tilt, valueStr);
  93.             pane->SetDescriptor(valueStr);
  94.         }
  95.         pane = (LEditField *)FindPaneByID(Edit_Zoom);
  96.         if (pane != nil)
  97.         {
  98.             pane->SetKeyFilter(CKeyFilters::RealNumberFieldPositive);
  99.             FixedToStr((*prefs)->zoom, valueStr);
  100.             pane->SetDescriptor(valueStr);
  101.         }
  102.     }
  103.     
  104.         // find and listen to the buttons
  105.     LButton *button;
  106.     button = (LButton *)FindPaneByID(Button_MakeDefault);
  107.     ThrowIfNil_(button);
  108.     button->AddListener(this);
  109.     
  110.     button = (LButton *)FindPaneByID(Button_SetTileFile);
  111.     ThrowIfNil_(button);
  112.     button->AddListener(this);
  113.     
  114.     button = (LButton *)FindPaneByID(Button_SetVRFile);
  115.     ThrowIfNil_(button);
  116.     button->AddListener(this);
  117.     
  118.     button = (LButton *)FindPaneByID(Button_Compression);
  119.     ThrowIfNil_(button);
  120.     button->AddListener(this);
  121.     
  122.     SetCompressionText(FindPaneByID(Caption_Compression), mCodec, mSpatialQuality);
  123. }
  124.  
  125.  
  126. void CPict2VRWindow::SetPictFile(
  127.     FSSpec *inMacFSSpec)
  128. {
  129.     P2VRPrefsHdl prefs = gApp->GetPreferences();
  130.     
  131.     try
  132.     {
  133.             // set the source pict file caption
  134.         mSrcSpec = *inMacFSSpec;
  135.         LPane *pictFileCaption = FindPaneByID(Caption_PictFile);
  136.         ThrowIfNil_(pictFileCaption);
  137.         Str255 pathStr;
  138.         GetFullPathName(inMacFSSpec, pathStr);
  139.         SetSizedDescriptor(this, Caption_PictFile, pathStr);
  140.         
  141.             // read the pict's frame to use for checking pan parameters
  142.         ReadPictFrame(*inMacFSSpec, mPictFrame);
  143.         
  144.         unsigned char charspace;
  145.         
  146.             // set a default tile file
  147.         mTileSpec = *inMacFSSpec;
  148.         if (prefs != nil)
  149.         {
  150.             charspace = 31 - (*prefs)->tileSuffix[0];
  151.             if (mTileSpec.name[0] > charspace)
  152.                 mTileSpec.name[0] = charspace;
  153.             ConcatPStr(mTileSpec.name, (*prefs)->tileSuffix);
  154.         }
  155.         else
  156.         {
  157.             charspace = 31 - 5;
  158.             if (mTileSpec.name[0] > charspace)
  159.                 mTileSpec.name[0] = charspace;
  160.             ConcatPStr(mTileSpec.name, "\p.tile");
  161.         }
  162.         GetFullPathName(&mTileSpec, pathStr);
  163.         SetSizedDescriptor(this, Caption_TileFile, pathStr);
  164.         
  165.             // set a default dest file
  166.         mDestSpec = *inMacFSSpec;
  167.         if (prefs != nil)
  168.         {
  169.             charspace = 31 - (*prefs)->movieSuffix[0];
  170.             if (mDestSpec.name[0] > charspace)
  171.                 mDestSpec.name[0] = charspace;
  172.             ConcatPStr(mDestSpec.name, (*prefs)->movieSuffix);
  173.         }
  174.         else
  175.         {
  176.             charspace = 31 - 4;
  177.             if (mDestSpec.name[0] > charspace)
  178.                 mDestSpec.name[0] = charspace;
  179.             ConcatPStr(mDestSpec.name, "\p.snm");
  180.         }
  181.         GetFullPathName(&mDestSpec, pathStr);
  182.         SetSizedDescriptor(this, Caption_QTVRFile, pathStr);
  183.         
  184.         SetDescriptor(inMacFSSpec->name);
  185.         
  186.         Show();
  187.     }
  188.     catch (ExceptionCode err)
  189.     {
  190.         delete this;
  191.         throw(err);
  192.     }
  193. }
  194.  
  195.  
  196. /* CPict2VRWindow::ListenToMessage
  197.  
  198.     Listen in on what is happening in the user interface.
  199. */
  200. void CPict2VRWindow::ListenToMessage(
  201.     MessageT inMessage,
  202.     void *ioParam)
  203. {
  204.     switch (inMessage)
  205.     {
  206.         case Button_Create:
  207.         {
  208.             MovieMakinRec params;
  209.             LPane
  210.                 *widthEdit = FindPaneByID(Edit_Width),
  211.                 *heightEdit = FindPaneByID(Edit_Height),
  212.                 *panEdit = FindPaneByID(Edit_Pan),
  213.                 *tiltEdit = FindPaneByID(Edit_Tilt),
  214.                 *zoomEdit = FindPaneByID(Edit_Zoom);
  215.             Str255 valueStr;
  216.             params.width = widthEdit->GetValue();
  217.             params.height = heightEdit->GetValue();
  218.             panEdit->GetDescriptor(valueStr);
  219.             params.pan = StrToFixed(valueStr);
  220.             tiltEdit->GetDescriptor(valueStr);
  221.             params.tilt = StrToFixed(valueStr);
  222.             zoomEdit->GetDescriptor(valueStr);
  223.             params.zoom = StrToFixed(valueStr);
  224.             params.srcSpec = mSrcSpec;
  225.             params.tileSpec = mTileSpec;
  226.             params.destSpec = mDestSpec;
  227.             params.codec = mCodec;
  228.             params.spatialQuality = mSpatialQuality;
  229.             params.depth = mDepth;
  230.             
  231.             BroadcastMessage(msg_MakeMovie, ¶ms);
  232.             
  233.             if (!params.completed)
  234.                 break;
  235.             // else fall through
  236.         }
  237.         
  238.         case Button_Cancel:
  239.             delete this;
  240.             break;
  241.         
  242.         case Button_Compression:
  243.         {
  244.             ComponentInstance ci = 
  245.                 ::OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
  246.             ThrowIfNil_(ci);
  247.             
  248.             try
  249.             {
  250.                 ComponentResult result;
  251.                 
  252.                 SCSpatialSettings ss;
  253.                 ss.codecType = mCodec;
  254.                 ss.spatialQuality = mSpatialQuality;
  255.                 ss.depth = mDepth;
  256.                 ss.codec = nil;
  257.                 result = ::SCSetInfo(ci, scSpatialSettingsType, &ss);
  258.                 ThrowIf_(result < 0);
  259.                 
  260.                 LFile srcPictFile(mSrcSpec);
  261.                 Int16 fileRef;
  262.                 try
  263.                 {
  264.                     
  265.                     fileRef = srcPictFile.OpenDataFork(fsRdPerm);
  266.                     OSErr err = ::SCSetTestImagePictFile(ci, fileRef, nil, scPreferCropping);
  267.                     ThrowIfOSErr_(err);
  268.                 }
  269.                 catch (ExceptionCode inErr2)
  270.                 {
  271.                     srcPictFile.CloseDataFork();
  272.                     
  273.                     throw(inErr2);
  274.                 }
  275.                 
  276.                 result = ::SCRequestImageSettings(ci);
  277.                 srcPictFile.CloseDataFork();
  278.                 ThrowIf_(result < 0);
  279.                 
  280.                 if (result != scUserCancelled)
  281.                 {
  282.                     result = ::SCGetInfo(ci, scSpatialSettingsType, &ss);
  283.                     ThrowIf_(result < 0);
  284.                     mCodec = ss.codecType;
  285.                     mSpatialQuality = ss.spatialQuality;
  286.                     mDepth = ss.depth;
  287.                     
  288.                     SetCompressionText(FindPaneByID(Caption_Compression), mCodec, mSpatialQuality);
  289.                 }
  290.             }
  291.             catch (ExceptionCode inErr)
  292.             {
  293.                 ::CloseComponent(ci);
  294.                 ReportError(inErr, err_ErrorSettingCompression);
  295.             }
  296.             
  297.             ::CloseComponent(ci);
  298.             break;
  299.         }
  300.         
  301.         case Button_SetTileFile:
  302.         {
  303.             StandardFileReply reply;
  304.             
  305.             ::UDesktop::Deactivate();
  306.             ::StandardPutFile("\pTile destination file:", "\p", &reply);
  307.             ::UDesktop::Activate();
  308.             
  309.             if (reply.sfGood)
  310.             {
  311.                 FSSpec parentSpec;
  312.                 (void)GetFileParent(&reply.sfFile, &parentSpec);
  313.                 Str255 descStr;
  314.                 GetFullPathName(&parentSpec, descStr);
  315.                 ConcatPStr(descStr, reply.sfFile.name);
  316.                 
  317.                 SetSizedDescriptor(this, Caption_TileFile, descStr);
  318.                 mTileSpec = reply.sfFile;
  319.             }
  320.             break;
  321.         }
  322.         
  323.         case Button_SetVRFile:
  324.         {
  325.             StandardFileReply reply;
  326.             
  327.             ::UDesktop::Deactivate();
  328.             ::StandardPutFile("\pQTVR destination file:", "\p", &reply);
  329.             ::UDesktop::Activate();
  330.             
  331.             if (reply.sfGood)
  332.             {
  333.                 FSSpec parentSpec;
  334.                 (void)GetFileParent(&reply.sfFile, &parentSpec);
  335.                 Str255 descStr;
  336.                 GetFullPathName(&parentSpec, descStr);
  337.                 ConcatPStr(descStr, reply.sfFile.name);
  338.                 
  339.                 SetSizedDescriptor(this, Caption_QTVRFile, descStr);
  340.                 mDestSpec = reply.sfFile;
  341.             }
  342.             break;
  343.         }
  344.         
  345.         case Button_MakeDefault:
  346.         {
  347.             P2VRPrefsHdl prefs = gApp->GetPreferences();
  348.             if (prefs != nil)
  349.             {
  350.                 (*prefs)->depth = mDepth;
  351.                 (*prefs)->codec = mCodec;
  352.                 (*prefs)->spatialQuality = mSpatialQuality;
  353.                 (*prefs)->width = GetValueForPaneID(Edit_Width);
  354.                 (*prefs)->height = GetValueForPaneID(Edit_Height);
  355.             }
  356.             break;
  357.         }
  358.         
  359.         default:
  360.             
  361.             LDialogBox::ListenToMessage(inMessage, ioParam);
  362.     }
  363. }
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.